import {Injectable} from "@angular/core";
import 'rxjs/add/operator/map';
import {Http, RequestOptions} from "@angular/http";
import {UrlData} from "../../common/urldata";
import {ExceptionHandler} from "../../common/exception.handler";
import {UserData} from "../../common/user.data";
/**
 * 收藏
 */
@Injectable()
export class ArticleService {

  constructor(private http: Http,private user: UserData, private exceptionHandler: ExceptionHandler, private urlData: UrlData) {
  }

  findByCode(code: string) {
    return this.http
      .get(this.urlData.baseUrl + `v1/article/` + code)
      .map(response => response.json());
  }

  findMyCreator(params: any) {
    params.token = this.user.token;
    return this.http
      .get(this.urlData.baseUrl + `v1/article/user/` + this.user.token)
      .map(response => response.json())
      .catch(err => this.exceptionHandler.handleError(err));
  }

  findArticlePage(code: string) {
    let headers = new Headers({"Accept": "text/html"});
    let options = new RequestOptions(headers);
    return this.http
      .get(this.urlData.baseUrl + `app/article/` + code, options)
      .map(response => {
        debugger
        return response.text()
      });
  }
}
